package com.chixing.consumer;

import com.chixing.config.RabbitMQConfiguration;
import com.chixing.pojo.Coupon;
import com.chixing.service.CouponService;
import com.chixing.util.ServerResponse;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class CouponConsumer {
    @Autowired
    private CouponService couponService;

    @RabbitListener(queues = RabbitMQConfiguration.deadQueuecoupon )//设置订单失效的队列

    public void process(Coupon coupon, Message message, @Headers Map<String, Object> headers, Channel channel) throws IOException {

        Coupon coupon1 = couponService.getByKey(coupon.getCouponOther1());

        if (coupon1.getCouponStatus() ==  0){
            coupon1.setCouponStatus(2);

        }
        System.out.println(coupon1);
        ServerResponse serverResponse = couponService.update(coupon1);

    }

}
